<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>-->
    <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
    <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
    <!--[endif]-->
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
    <style>
        .layui-input-inline,.buttondiv .layui-input-inline {
            float: left;
            width: 450px !important;
            margin-right: 10px;
        }
        .error{
            color: red;
            line-height: 20px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form"  id="orgroleform" lay-filter="orgroleform">
            <input type="hidden" name="id">
            <div class="layui-form-item">
                <label class="layui-form-label" for="name"><span style="color: red;">*</span>角色名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" id="name"  placeholder="请输入角色名称" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="sort"><span style="color: red;">*</span>排&emsp;&emsp;序</label>
                <div class="layui-input-inline">
                    <input type="text" name="sort" id="sort"  placeholder="请输入排序" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" for="orgType"><span style="color: red;">*</span>组织类型</label>
                    <div class="layui-input-inline">
                        <select id="orgType" name="orgType"></select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" for="description">备&emsp;&emsp;注</label>
                    <div class="layui-input-inline">
                        <textarea name="description" id="description" placeholder="请输入内容" class="layui-textarea" ></textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    var AUflag;//1为保存2为更新
    $(function () {
        loadOrgType();
    })

    function loadOrgType(){
        layui.use("form",function() {
            var form = layui.form;
            publicAjax (null,'infdictitem/selectInfdictitemByInfdictsortCode',{code:'OrgType'},null,null,function(r){
                if(r.code==2000){
                    var data = r.data;
                    var option = "";
                    $.each(data,function(i,e){
                        option += "<option value='"+e.code+"'>"+e.name+"</option>";
                    })
                    $("#orgType").html(option);
                }
                form.render();
            })
        })
    }
    /**
     * 验证
     */
    function voluate(flag,data) {
        AUflag = flag;
        if(flag != 1){//更新
            layui.use("form",function(){
                var form = layui.form;
                form.val("orgroleform",{
                    "name":data.name,
                    "orgType":data.orgType,
                    "sort":data.sort,
                    "description":data.description,
                    "id":data.id
                })
                form.render();
            })
        }

    }
    /**
     * 添加按钮
     */
    function submit(){
        var data = $("#orgroleform").serializeJson();
        var url = 'orgrole/insertOrgRole';
        var obj = $(validform().form());
        delete data.id;
        if(!obj[0]){
            return false;
        }
        var result;
        publicAjax (null,url,data,false,null,function (r) {
            if(r.code==2000){
                laysuccess("添加成功",null);
                result = r;
            }else{
                layerror("添加失败",null);
                result = r;
            }
        });
        return result;
    }
    /**
     * 更新按钮
     */
    function updateInfdict(){
        var data = $("#orgroleform").serializeJson();
        delete data.pid;
        var url = 'orgrole/updateOrgRole';
        var obj = $(validform().form());
        if(!obj[0]){
            return false;
        }
        var result;
        publicAjax (null,url,data,false,null,function (r) {
            if(r.code==2000){
                laysuccess("修改成功",null);
                result = r;
            }else{
                layerror("修改失败",null);
                result = r;
            }
        });
        return result;
    }

    //编写表单验证函数validform，在验证按钮注册按钮点击事件内调用验证函数对象
    function validform(flag){//flag 1保存2更新;
        return $("#orgroleform").validate({
            rules : {
                name : {
                    required:true,
                    normalizer: function( value ) {
                        return $.trim( value );
                    }
                },
                sort:{
                    required:true,
                    number:true,
                    normalizer: function( value ) {
                        return $.trim( value );
                    }
                },
                orgType: {
                    required:true,
                    normalizer: function( value ) {
                        return $.trim( value );
                    }
                },
                description: {
                    maxlength: 100,
                    normalizer: function( value ) {
                        return $.trim( value );
                    }
                },
            },
            messages : {
                name : {
                    required: "角色名称不能为空"
                },
                sort : {
                    required:"排序不能为空",
                },
                orgType:{
                    required: "所属组织不能为空",
                },
                description : {
                    maxlength: "备注长度不可超过100"
                }
            }
        });
    }


</script>
</body>

</html>
